package com.mall.orders.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.model.domain.OmsOrderReturnApply;
import com.mall.model.vo.CommonPage;
import com.mall.orders.mapper.OmsOrderReturnApplyMapper;
import com.mall.orders.service.OmsOrderReturnApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 订单退货申请(OmsOrderReturnApply)表服务实现类
 *
 * @author wishmumu
 * @since 2023-03-11 15:42:55
 */
@Service
public class OmsOrderReturnApplyService {
    @Autowired
    private OmsOrderReturnApplyMapper omsOrderReturnApplyMapper;

    public CommonPage selectAll(Integer pageNum, Integer pageSize, Integer status, String createTime, String handleMan, String handleTime, String receiverKeyword) {
        Integer page = (pageNum-1) *pageSize;
        List<OmsOrderReturnApply> returnApplyList = omsOrderReturnApplyMapper.selectAll(page, pageSize, status, createTime, handleMan, handleTime, receiverKeyword);
        Integer count = omsOrderReturnApplyMapper.count(pageNum, pageSize, status, createTime, handleMan, handleTime, receiverKeyword);
        return new CommonPage(pageNum, pageSize, count, returnApplyList);
    }

    public OmsOrderReturnApply getById(Integer id) {
        return omsOrderReturnApplyMapper.getById(id);
    }

    public void update(Integer id, OmsOrderReturnApply omsOrderReturnApply) {
        if (omsOrderReturnApply.getHandleMan()!=null) {
            omsOrderReturnApply.setHandleTime(new Date(System.currentTimeMillis()));
        }
        if (omsOrderReturnApply.getReceiveMan()!=null) {
            omsOrderReturnApply.setReceiveTime(new Date(System.currentTimeMillis()));
        }
        omsOrderReturnApplyMapper.updateById(id, omsOrderReturnApply);
    }

    public void delete(List<Integer> ids) {
        omsOrderReturnApplyMapper.deleteBatchIds(ids);
    }
}

